﻿
''' <summary>
''' Sửa chữa tài sản
''' </summary>
''' <remarks></remarks>
Public Class RepairDTO
    Inherits Repair_X

    Private _id As Integer ' Mã tài sản
    Private _repairOrg As Integer 'Đại diện đơn vị sửa chữa
    Private _faOrg As Integer ' Đại diện đơn vị sở hữu tài sản
    Private _date As Date ' Thời gian
    Private _partRepair As String ' Bộ phận sửa chữa
    Private _contentRepair As String ' Nội dung sửa chữa
    Private _intendedCost As Integer ' Giá dự toán
    Private _realCost As Integer ' Chi phí thực tế
    Private _resultTest As Integer ' Kết quả kiểm tra
    Private _fatype As Integer ' Loại tài sản cố định
    Private _status As Integer ' Trạng thái chứng từ

    Private _behave As Integer

    Public Sub New(ByVal id As Integer, ByVal repairOrg As Integer, ByVal faOrg As Integer, ByVal date1 As Date, ByVal partRepair As String, ByVal contentRepair As String, ByVal intendedCost As Integer, ByVal realCost As Integer, ByVal resultTest As Integer, ByVal fatype As Integer)

        Me._id = id
        Me._repairOrg = repairOrg
        Me._faOrg = faOrg
        Me._date = date1
        Me._partRepair = partRepair
        Me._contentRepair = contentRepair
        Me._intendedCost = intendedCost
        Me._realCost = realCost
        Me._resultTest = resultTest
        Me._fatype = fatype
        Me._status = CONSTANT.STATUS._DRAFTS

        Me._behave = CONSTANT.BEHAVE_TYPE._INSERT
    End Sub

    Public Sub New(ByVal id As Integer)

        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect
        Dim aSql As String
        aSql = "SELECT *FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & id & " "

        Dim da As DataTable
        da = New DataTable
        da = myConnect.executeQuery(aSql)
        If (da Is Nothing) Then
            Return
        End If

        Me._id = CType(da.Rows(0)(MyBase.COLUMN_NAME_id), Integer)
        Me._repairOrg = CType(da.Rows(0)(MyBase.COLUMN_NAME_repairOrg), String)
        Me._faOrg = CType(da.Rows(0)(MyBase.COLUMN_NAME_faOrg), String)
        Me._date = CType(da.Rows(0)(MyBase.COLUMN_NAME_date), Date)
        Me._partRepair = CType(da.Rows(0)(MyBase.COLUMN_NAME_partRepair), String)
        Me._contentRepair = CType(da.Rows(0)(MyBase.COLUMN_NAME_contenRepair), String)
        Me._intendedCost = CType(da.Rows(0)(MyBase.COLUMN_NAME_intendedCost), Integer)
        Me._realCost = CType(da.Rows(0)(MyBase.COLUMN_NAME_realCost), Integer)
        Me._resultTest = CType(da.Rows(0)(MyBase.COLUMN_NAME_resultTest), String)
        Me._fatype = CType(da.Rows(0)(MyBase.COLUMN_NAME_fatype), Integer)
        Me._status = CType(da.Rows(0)(MyBase.COLUMN_NAME_status), Integer)


        Me._behave = CONSTANT.BEHAVE_TYPE._UPDATE
    End Sub

    Public Function save() As Boolean
        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect
        Dim aSql As String
        aSql = ""

        Select Case Me._behave
            Case CONSTANT.BEHAVE_TYPE._UPDATE
                aSql = "UPDATE " & MyBase.TABLE_NAME & ""
                aSql += " SET " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                aSql += " ," & MyBase.COLUMN_NAME_repairOrg & " = " & Me._repairOrg & ""
                aSql += " ," & MyBase.COLUMN_NAME_faOrg & " = " & Me._faOrg & ""
                aSql += " ," & MyBase.COLUMN_NAME_date & " = " & Me._date & ""
                aSql += " ," & MyBase.COLUMN_NAME_partRepair & " = " & Me._partRepair & ""
                aSql += " ," & MyBase.COLUMN_NAME_contenRepair & " = " & Me._contentRepair & ""
                aSql += " ," & MyBase.COLUMN_NAME_intendedCost & " = " & Me._intendedCost & ""
                aSql += " ," & MyBase.COLUMN_NAME_realCost & " = " & Me._realCost & ""
                aSql += " ," & MyBase.COLUMN_NAME_resultTest & " = " & Me._resultTest & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & " = " & Me._fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & " = " & Me._status & ""
                aSql += " WHERE  " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                Return myConnect.executeUpdate(aSql)
            Case CONSTANT.BEHAVE_TYPE._INSERT
                aSql = "INSERT INTO " & MyBase.TABLE_NAME & ""
                aSql += "("
                aSql += " ," & MyBase.COLUMN_NAME_id & ""
                aSql += " ," & MyBase.COLUMN_NAME_repairOrg & ""
                aSql += " ," & MyBase.COLUMN_NAME_faOrg & ""
                aSql += " ," & MyBase.COLUMN_NAME_date & ""
                aSql += " ," & MyBase.COLUMN_NAME_partRepair & ""
                aSql += " ," & MyBase.COLUMN_NAME_contenRepair & ""
                aSql += " ," & MyBase.COLUMN_NAME_intendedCost & ""
                aSql += " ," & MyBase.COLUMN_NAME_realCost & ""
                aSql += " ," & MyBase.COLUMN_NAME_resultTest & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & ""
                aSql += " )"
                aSql += " VALUES("
                aSql += " " & Me._id & ""
                aSql += " ," & Me._repairOrg & ""
                aSql += " ," & Me._faOrg & ""
                aSql += " ," & Me._date & ""
                aSql += " ," & Me._partRepair & ""
                aSql += " ," & Me._contentRepair & ""
                aSql += " ," & Me._intendedCost & ""
                aSql += " ," & Me._realCost & ""
                aSql += " ," & Me._resultTest & ""
                aSql += " ," & Me._fatype & ""
                aSql += " ," & Me._status & ""
                aSql += " )"
                Return myConnect.executeUpdate(aSql)

            Case Else

        End Select
    End Function

    Public Function delete() As Boolean
        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect

        Dim aSql As String
        aSql = "DELETE FROM " & MyBase.TABLE_NAME & ""
        aSql += "WHERE " & MyBase.COLUMN_NAME_id & " =" & Me._id & ""
        Return myConnect.executeUpdate(aSql)
    End Function

    Public Property id() As Integer
        Get
            Return Me._id
        End Get
        Set(ByVal value As Integer)
            Me._id = value
        End Set
    End Property

    Public Property repairOrg() As Integer
        Get
            Return Me._repairOrg
        End Get
        Set(ByVal value As Integer)
            Me._repairOrg = value
        End Set
    End Property

    Public Property faOrg() As Integer
        Get
            Return Me._faOrg
        End Get
        Set(ByVal value As Integer)
            Me._faOrg = value
        End Set
    End Property

    Public Property datedate() As Date
        Get
            Return Me._date
        End Get
        Set(ByVal value As Date)
            Me._date = value
        End Set
    End Property

    Public Property contentRepair() As String
        Get
            Return Me._contentRepair
        End Get
        Set(ByVal value As String)
            Me._contentRepair = value
        End Set
    End Property

    Public Property intendedCost() As Integer
        Get
            Return Me._intendedCost
        End Get
        Set(ByVal value As Integer)
            Me._intendedCost = value
        End Set
    End Property

    Public Property realCost() As Integer
        Get
            Return Me._realCost
        End Get
        Set(ByVal value As Integer)
            Me._realCost = value
        End Set
    End Property

    Public Property resultTest() As String
        Get
            Return Me._resultTest
        End Get
        Set(ByVal value As String)
            Me._resultTest = value
        End Set
    End Property

    Public Property fatype() As Integer
        Get
            Return Me._fatype
        End Get
        Set(ByVal value As Integer)
            Me._fatype = value
        End Set
    End Property

    Public Property status() As Integer
        Get
            Return Me._status
        End Get
        Set(ByVal value As Integer)
            Me._status = value
        End Set
    End Property

End Class
